package com.jtlrm.ckd.mvp.view.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.base.sdk.util.ImageUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jtlrm.ckd.R;
import com.jtlrm.ckd.entity.DataShenHeEntity;
import com.jtlrm.ckd.entity.NewsEntity;
import com.jtlrm.ckd.mvp.view.activity.ShuJuShenHeDetailActivity;

public class ShuJuShenHeAdapter extends BaseQuickAdapter<DataShenHeEntity, BaseViewHolder> {

    private boolean isEdite = false;


    private UpdateSelect updateSelect;

    public void setUpdateSelect(UpdateSelect updateSelect) {
        this.updateSelect = updateSelect;
    }

    public ShuJuShenHeAdapter() {
        super(R.layout.shuju_shenhe_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, final DataShenHeEntity item) {
        ImageUtil.loadCircleAvatarImage((ImageView) helper.getView(R.id.avatar), item.getHeadPicture());
        helper.setText(R.id.name, item.getName());
        helper.setText(R.id.sex, item.getSex());
        helper.setText(R.id.age, item.getAge() + "岁");
        helper.setText(R.id.date, item.getCreateTime());
        final CheckBox checkBox = helper.getView(R.id.check);
        if (isEdite) {
            checkBox.setVisibility(View.VISIBLE);
            checkBox.setChecked(item.isSelected());
            helper.getView(R.id.container).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    checkBox.setChecked(!item.isSelected());
                    item.setSelected(!item.isSelected());
                    if (updateSelect != null) {
                        updateSelect.update();
                    }
                }
            });
        } else {
            checkBox.setVisibility(View.GONE);
            helper.getView(R.id.container).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ShuJuShenHeDetailActivity.goDetail(mContext, item.getTreatmentId(), item.getMeasureDate(), item.getPatientId());
                }
            });
        }
    }

    /**
     * 设置是否是审核状态
     *
     * @param isEdite
     */
    public void setEdite(boolean isEdite) {
        this.isEdite = isEdite;
        notifyDataSetChanged();
    }

    public boolean isEdite() {
        return isEdite;
    }

    public interface UpdateSelect {
        void update();
    }
}

